<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Clock</title>
    <script type="text/javascript">
        // 定义和创建显示数字时钟的函数
        function startTime() {
            var today = new Date();
            var hour = today.getHours();
            var minute = today.getMinutes();
            var second = today.getSeconds();

            minute = checkTime(minute);
            second = checkTime(second);

            document.getElementById("clock").innerHTML = hour + ":" + minute + ":" + second;
            var t = setTimeout("startTime()", 500);
        }

        function checkTime(i) {
            if (i < 10) {
                i = "0" + i;
            }
            return i;
        }
    </script>
</head>
<body onload="startTime()">
<div style="color: red;font-weight: bold;" id="clock"></div>
</body>
</html>